<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <link rel="stylesheet"
          href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/css/ol.css"
          type="text/css">
    <style>
        .layui-input-block button {
            margin: 0 10px;
        }

        .map {
            height: 480px;
            width: 100%;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-row layui-col-space10">
            <form class="layui-form layui-form-pane layui-col-lg8" action="">
                <div class="layui-form-item">
                    <label class="layui-form-label required">管路名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" lay-verify="required" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item" pane>
                    <label class="layui-form-label">
					<span>
						管路信息 <i class="layui-icon" id="tip"
                                style="vertical-align: -10%;" lay-event="tip">&#xe60b;</i>
					</span>
                    </label>
                    <div class="layui-input-block">
                        <input type="hidden" name="xlsFileName" id="excelFile">
                        <button type="button" class="layui-btn" id="uploadExcel">
                            <i class="layui-icon">&#xe67c;</i>上传文档
                        </button>
                        <span id="excelName"></span>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">基准点位</label>
                    <div class="layui-input-block">
                        <input type="text" name="referencePoint" autocomplete="off"
                               class="layui-input" placeholder="默认为管路、支路首支传感器">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">泄漏标准</label>
                    <div class="layui-input-block">
                        <input type="text" name="standard" lay-verify="required|number" autocomplete="off"
                               class="layui-input" placeholder="管路泄漏判断标准">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">持续时间</label>
                    <div class="layui-input-block">
                        <input type="text" name="duration" lay-verify="required|number" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use(['form', 'upload', 'util'], function () {
        var form = layui.form
            , layer = layui.layer
            , util = layui.util
            , $ = layui.$
            , upload = layui.upload;


        var fileName;
        //执行实例
        upload.render({
            elem: '#uploadExcel' //绑定元素
            , url: '/file/uploadFile' //改成您自己的上传接口
            , auto: true
            , accept: 'file'
            , acceptMime: 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
            , field: 'file'
            , done: function (res) {
                console.log(res)
                var code = res.code === 0 ? 1 : 2;
                if (res.code === 0) {
                    $("#excelFile").val(res.data.title);
                    return layer.msg("上传成功", {icon: code});
                } else {
                    return layer.msg("上传失败", {icon: code});
                }
            }
            , error: function (res) {
                return layer.msg("上传成功", {icon: 2});
            }
            , before: function (obj) {
                obj.preview(function (index, file, result) {
                    fileName = file.name;
                    $("#excelName").text(file.name)
                });
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            /*layer.alert(JSON.stringify(data.field));*/
            let loadingIndex;
            $.ajax({
                type: "POST",
                url: '/pipeline/insert',
                data: data.field,
                beforeSend: function () {
                    loadingIndex = layer.load(2);
                },
                success: function (res) {
                    layer.close(loadingIndex);
                    if (res.code === 0) {
                        layer.msg('新增成功', {icon: 1});
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                        parent.layui.table.reload('currentTableId', {
                            page: {
                                curr: 1
                            }
                        })
                    } else {
                        layer.msg('新增失败,稍后重试', {icon: 1});
                    }
                }
            });
            return false;
        });


        //Tip点击事件
        util.event('lay-event', {
            tip: function () {
                layer.tips('<a href="http://47.95.231.180:88/file/download?path=batchAddEquipment' +
                    '/%E6%89%B9%E9%87%8F%E6%B7%BB%E5%8A%A0%E8%AE%BE%E5%A4%87%E6%A8%A1%E6%9D%BF.xlsx">Excel模板</a>', '#tip', {
                    tips: [1, '#3595CC'],
                    time: 4000,
                    success: function (layero, index) {
                        var oldLeft = layero.css('left');
                        oldLeft = oldLeft.substring(0, oldLeft.indexOf('px'));
                        layero.css('left', (oldLeft - 10) + 'px');
                    }
                });
            }
        });
    });
</script>

</body>
</html>
